const cloud = require('wx-server-sdk');

cloud.init({
  env: cloud.DYNAMIC_CURRENT_ENV
});
const db = cloud.database();

// 查询数据库集合云函数入口函数
exports.main = async (event, context) => {
  console.log("detail func " + event);
  switch (event.action) {
    case 'add':
      try {
        console.log("add detail data" + JSON.stringify(event.data));
        return await db.collection('exercise_detail').add({
            // data 字段表示需新增的 JSON 数据
            data: event.data
          })
      } catch(e) {
        console.error('add exercise detail fail', e)
      }
      break;
    default:
      console.log("action " + event.action + "undefined")
  }
};
